package com.redpacketcover.rc.base;

import androidx.lifecycle.MutableLiveData;

import io.reactivex.observers.DisposableObserver;

public class BasicObserver<T> extends DisposableObserver<T> {

    private MutableLiveData liveData;
    private RxErrorHandler mErrorHandler;


    public BasicObserver(MutableLiveData mutableLiveData) {
        this.mErrorHandler = new RxErrorHandler();
        this.liveData = mutableLiveData;
    }


    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
        ApiException baseException = mErrorHandler.handleError(e);//网络异常
        BaseResponseBean bean = new BaseResponseBean();
        bean.setCode(baseException.getCode());
        bean.setMsg(baseException.getMsg());
        liveData.postValue(bean);
    }


    @Override
    public void onNext(T baseResponseBean) {
        liveData.postValue(baseResponseBean);
    }

    @Override
    public void onComplete() {

    }


}
